﻿using OSSUtility.Device;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Ozone.Device
{
    //润泽六通切换阀
    public class DevSV06 : DevBase
    {

        //COM
        public DevSV06(int CommType, string FSrvIP, int FPort) : base(CommType, FSrvIP, FPort)
        {

        }
        //修改地址的工厂指令  需要断电重启生效
        //CC 00 00 FF EE BB AA 01 00 00 00 DD FC 04


        //CC 01 44 01 00 DD EF 01       切阀   关蠕动泵
        //CC 01 44 02 00 DD F0 01       柱塞泵 加热泵 蠕动泵 动 

        /// <summary>
        ///   1号切换 
        ///   1-6   2-3  4-5   清洗
        ///   
        /// 2号切换
        ///  1-2 3-4 5-6   进液体
        /// </summary>
        /// <param name="nValveNO"></param>
        /// <returns></returns>
        public bool SwitchValve(int nValveNO)
        {


            //1: 清洗
            //2：进液体
            //3：关蠕动泵切换阀门液体进反应器
            //4：蠕动泵辅助吸液进废液瓶
            //CC 00 44 01 00 DD EE 01
            //CC 00 44 02 00 DD EF 01
            byte[] bytesData = new byte[] { 0xCC, 0x00, 0x44, 0x01, 0x00, 0xDD, 0xEE, 0x01 };

            if (nValveNO == 1)
            {
                bytesData = new byte[] { 0xCC, 0x00, 0x44, 0x01, 0x00, 0xDD, 0xEE, 0x01 };
            }

            if (nValveNO == 2)
            {
                bytesData = new byte[] { 0xCC, 0x00, 0x44, 0x02, 0x00, 0xDD, 0xEF, 0x01 };
            }

            if (nValveNO == 3)
            {
                bytesData = new byte[] { 0xCC, 0x01, 0x44, 0x01, 0x00, 0xDD, 0xEF, 0x01 };


            }

            if (nValveNO == 4)
            {
                bytesData = new byte[] { 0xCC, 0x01, 0x44, 0x02, 0x00, 0xDD, 0xF0, 0x01 };
            }

            byte[] RecvData = session_.sendAndReadByte(bytesData, 1000);

            if (RecvData == null)
                return false;

            if (RecvData.Length != 8)
                return false;

            return true;
        }
    }
}
